package com.anlogic.sdk.openocd;

import com.anlogic.sdk.utils.BitsUtils;

public class OpenocdInitParam {
	public static int JTAG_SPEED_OFFSET = 10;   // 14 bits,    set adapter speed
	public static int HWSERVER_OFFSET = 9;      //  1 bits,    0: hwserver disable; 1: hwserver enable
	public static int REMOTE_DEBUG_OFFSET = 8;  //  1 bits,    0: remote debug diable; 1: remote debug enable
	public static int JTAG_OFFSET = 7;          //  1 bits,    0: PLJTAG; 1: PJTAG
	public static int TARGET_RSV_OFFSET = 6;    //  1 bits,    0: rsvtap disable; 1: rsvtap enable
	public static int EMMC1_OFFSET = 4;         //  1 bits,    0: emmc1 disable; 1: emmc1 enable
	public static int QSPI_OFFSET = 2;          //  2 bits,    00: qspi disable; 01: qspi 0 enable; 11: qspi 0&1 enable
	public static int NAND_OFFSET = 1;          //  1 bits,    0: nand disable; 1: nand enable
	public static int EMMC_OFFSET = 0;          //  1 bits,    0: emmc disable; 1: emmc enable
	
	public static int maxJtagSpeed() {
		return (1 << 14) - 1;
	}
	
	public static int setJtagSpeed(int original, int value) {
		return BitsUtils.setBits(original, JTAG_SPEED_OFFSET + 14, JTAG_SPEED_OFFSET, value);
	}
	
	public static int getJtagSpeed(int original) {
		return BitsUtils.getBits(original, JTAG_SPEED_OFFSET + 14, JTAG_SPEED_OFFSET);
	}
	
	public static int setHwserver(int original, int value) {
		return BitsUtils.setBit(original, HWSERVER_OFFSET, value);
	}
	
	public static boolean getHwserver(int original) {
		return (BitsUtils.getBit(original, HWSERVER_OFFSET) == 1) ? true : false;
	}
	
	public static int setRemoteDebug(int original, int value) {
		return BitsUtils.setBit(original, REMOTE_DEBUG_OFFSET, value);
	}
	
	public static boolean getRemoteDebug(int original) {
		return (BitsUtils.getBit(original, REMOTE_DEBUG_OFFSET) == 1) ? true : false;
	}
	
	public static int setPJtag(int original, int value) {
		return BitsUtils.setBit(original, JTAG_OFFSET, value);
	}
	
	public static boolean getPJtag(int original) {
		return (BitsUtils.getBit(original, JTAG_OFFSET) == 1) ? true : false;
	}
	
	public static int setTargetRSV(int original, int value) {
		return BitsUtils.setBit(original, TARGET_RSV_OFFSET, value);
	}
	
	public static boolean getTargetRSV(int original) {
		return (BitsUtils.getBit(original, TARGET_RSV_OFFSET) == 1) ? true : false;
	}
	
	public static int setQspi(int original, int value) {
		return BitsUtils.setBit(original, QSPI_OFFSET, value);
	}
	
	public static boolean getQspi(int original) {
		return (BitsUtils.getBit(original, QSPI_OFFSET) == 1) ? true : false;
	}
	
	public static int setQspi1(int original, int value) {
		return BitsUtils.setBit(original, QSPI_OFFSET + 1, value);
	}
	
	public static boolean getQspi1(int original) {
		return (BitsUtils.getBit(original, QSPI_OFFSET + 1) == 1) ? true : false;
	}
	
	public static int setNand(int original, int value) {
		return BitsUtils.setBit(original, NAND_OFFSET, value);
	}
	
	public static boolean getNand(int original) {
		return (BitsUtils.getBit(original, NAND_OFFSET) == 1) ? true : false;
	}
	
	public static int setEmmc(int original, int value) {
		return BitsUtils.setBit(original, EMMC_OFFSET, value);
	}
	
	public static boolean getEmmc(int original) {
		return (BitsUtils.getBit(original, EMMC_OFFSET) == 1) ? true : false;
	}
	
	public static int setEmmc1(int original, int value) {
		return BitsUtils.setBit(original, EMMC1_OFFSET, value);
	}
	
	public static boolean getEmmc1(int original) {
		return (BitsUtils.getBit(original, EMMC1_OFFSET) == 1) ? true : false;
	}
}
